package genhandle

// 生成main文件
import (
	"fginTpl/fgin_layout_gen/config"
	"fginTpl/fgin_layout_gen/globals"
	"fginTpl/utils"
	"path/filepath"
)

func GenCmdV2() {
	tplParams := map[string]string{
		"ProjectName": config.ConfigData.ProjectName,
	}
	if err := utils.TourchFile(filepath.Join(globals.BASEDIR, "./cmd/main.go"), "./fgin_layout_v2_templates/cmd/main.tpl", "ginMainTpl", tplParams); err != nil {
		panic(err)
	}
	if err := utils.TourchFile(filepath.Join(globals.BASEDIR, "./cmd/wire_gen.go"), "./fgin_layout_v2_templates/cmd/wire_gen.tpl", "ginWireGenTpl", tplParams); err != nil {
		panic(err)
	}
	if err := utils.TourchFile(filepath.Join(globals.BASEDIR, "./cmd/wire.go"), "./fgin_layout_v2_templates/cmd/wire.tpl", "ginWireTpl", tplParams); err != nil {
		panic(err)
	}
}

func GenConfigsV2() {
	tplParams := map[string]string{
		"ProjectName": config.ConfigData.ProjectName,
	}
	if err := utils.TourchFile(filepath.Join(globals.BASEDIR, "./configs/cfg.yaml"), "./fgin_layout_v2_templates/configs/cfg.tpl", "ginCfgTpl", tplParams); err != nil {
		panic(err)
	}
}

func GenPbV2() {
	tplParams := map[string]string{}
	if err := utils.TourchFile(filepath.Join(globals.BASEDIR, "./pb/greeter.proto"), "./fgin_layout_v2_templates/pb/greeter.tpl", "ginPbTpl", tplParams); err != nil {
		panic(err)
	}
}

func GenDockerfileV2() {
	tplParams := map[string]string{
		"ProjectName": config.ConfigData.ProjectName,
	}
	if err := utils.TourchFile(filepath.Join(globals.BASEDIR, "./Dockerfile"), "./fgin_layout_v2_templates/Dockerfile.tpl", "ginDockerfileTpl", tplParams); err != nil {
		panic(err)
	}
}

func GenInternalV2() {
	tplParams := map[string]string{
		"ProjectName": config.ConfigData.ProjectName,
	}
	// 控制器部分
	if err := utils.TourchFile(filepath.Join(globals.BASEDIR, "./internal/controller/controller.go"), "./fgin_layout_v2_templates/internal/controller/controller.tpl", "ginControllerTpl", tplParams); err != nil {
		panic(err)
	}
	if err := utils.TourchFile(filepath.Join(globals.BASEDIR, "./internal/controller/greeter.go"), "./fgin_layout_v2_templates/internal/controller/greeter.tpl", "ginControllerGreeterTpl", tplParams); err != nil {
		panic(err)
	}
	// 路由部分
	if err := utils.TourchFile(filepath.Join(globals.BASEDIR, "./internal/router/router.go"), "./fgin_layout_v2_templates/internal/router/router.tpl", "ginRouterTpl", tplParams); err != nil {
		panic(err)
	}
	if err := utils.TourchFile(filepath.Join(globals.BASEDIR, "./internal/router/greeter.go"), "./fgin_layout_v2_templates/internal/router/greeter.tpl", "ginRouterGreeterTpl", tplParams); err != nil {
		panic(err)
	}
	// 服务部分
	if err := utils.TourchFile(filepath.Join(globals.BASEDIR, "./internal/service/service.go"), "./fgin_layout_v2_templates/internal/service/service.tpl", "ginServiceTpl", tplParams); err != nil {
		panic(err)
	}
	if err := utils.TourchFile(filepath.Join(globals.BASEDIR, "./internal/service/greeter.go"), "./fgin_layout_v2_templates/internal/service/greeter.tpl", "ginServiceGreeterTpl", tplParams); err != nil {
		panic(err)
	}
}
